<?php
namespace wow\model;


class GWStringParser extends \gnomephp\string\StringParser{
	
	public function __construct($text){
		parent::__construct($text);
		
		$this->addBBCodeCallback('item',
		function($item){
			$id = trim($item[1]);
			$r = \wow\modelauth\Realmlist::getFirstRealm();
		
			if (is_numeric($id)){
				$it = \wow\modelworld\ItemTemplate::getItemTemplate($r->id, (int)$id);
			}else{
				$it = \wow\modelworld\ItemTemplate::getItemTemplateByName($r->id, $id);
			}
			if ($it)return '<a href="http://us.battle.net/wow/en/item/'.$it->entry.'" style="color: '.$it->getColor().';">['.$it->name.']</a>';
			else return $id;
		}
		);
	}
}